﻿using System.Linq;
using DosTexPrj.Core.Models;
using DosTexPrj.Core.RepositoriesInterface;
using NUnit.Framework;

namespace DosTexPrj.Implement.NHibernate.Test.Repositories
{
    [TestFixture]
    public class TestRoleRepository : RepositoryFixtureBase
    {
        private IRoleRepository _roleRepository;

        protected override void Context()
        {
            this._roleRepository = MyServiceLocator.DoGetInstance<IRoleRepository>();
        }

        [Test]
        public void Can_Create_Role()
        {
            var role = new Role { RoleName = "Customer" };
            var user = new User
            {
                FirstName = "Kim",
                LastName = "Kim",
                Username = "Kim",
                Password = "Kim",
                Role = role
            };
            role.UsersOfRole.Add(user);
            role = this._roleRepository.Save<Role>(role);
            Assert.IsTrue(role != null && role.Id > 0 && role.UsersOfRole.Count > 0);
        }

        [Test]
        public void Can_Retrieve_Role_By_Key()
        {
            var role = this._roleRepository.FindByKey<Role>(1);
            Assert.IsTrue(role != null && role.Id == 1);
        }

        [Test]
        public void Can_Retrieve_Role_By_Condition()
        {
            var roles = this._roleRepository.FindByCondition<Role>(x => x.RoleName.Contains("C"));
            Assert.IsTrue(roles != null && roles.ToList().Count > 0);
        }

        [Test]
        public void Can_Retrieve_All_Role()
        {
            var roles = this._roleRepository.GetAll<Role>();
            Assert.IsTrue(roles != null && roles.ToList().Count > 0);
        }
    }
}